<?php

/**
 * This is the model class for table "adm_group".
 *
 * The followings are the available columns in table 'adm_group':
 * @property string $id_adm_group
 * @property string $code
 * @property string $name
 * @property string $active
 * @property string $group_level
 *
 * The followings are the available model relations:
 * @property AdmGroupMenu[] $admGroupMenus
 * @property AdmUser[] $admUsers
 */
class AdmGroup extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return AdmGroup the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'adm_group';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('code', 'length', 'max'=>50),
			array('name', 'length', 'max'=>100),
			array('active', 'length', 'max'=>1),
			array('group_level', 'length', 'max'=>19),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_adm_group, code, name, active, group_level', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'admGroupMenus' => array(self::HAS_MANY, 'AdmGroupMenu', 'id_adm_group'),
			'admUsers' => array(self::HAS_MANY, 'AdmUser', 'id_adm_group'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_adm_group' => 'Id Adm Group',
			'code' => 'Code',
			'name' => 'Name',
			'active' => 'Active',
			'group_level' => 'Group Level',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_adm_group',$this->id_adm_group,true);
		$criteria->compare('code',$this->code,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('active',$this->active,true);
		$criteria->compare('group_level',$this->group_level,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}